import { createRouter,createWebHistory } from 'vue-router'
const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: '/home',
      meta: {
        title: '首页'
      },
    },
    {
      path: '/home',
      name: 'home',
      meta: {
        title: '首页',
        name: 'home',
        isTab: true
      },
      component: () => import('../pages/Home.vue')
    },
    {
      path: '/category',
      name: 'category',
      meta: {
        title: '分类',
        name: 'category',
        isTab: true,
        isShowNav: true
      },
      component: () => import('../pages/Category.vue')
    },
    {
      path: '/cart',
      name: 'cart',
      meta: {
        title: '购物车',
        name: 'cart',
        isTab: true,
        isShowNav: true,
        isShowBack: true
      },
      component: () => import('../pages/Cart.vue')
    },
    {
      path: '/user',
      name: 'user',
      meta: {
        title: '我的',
        isTab: true
      },
      component: () => import('../pages/User.vue')
    },
    {
      path: '/message',
      name: 'message',
      meta: {
        title: '消息',
        isTab: true,
        isShowNav: true
      },
      component: () => import('../pages/Message.vue')
    }
  ]
})
router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title
  if (title) {
    document.title = title+'-微商城'
  }
  next()
})
export default router
